package models;

import java.util.Date;
import java.util.LinkedList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;

import play.db.jpa.Model;

@Entity
public class Activity extends Model {

	public String name;

	@ManyToMany(mappedBy = "activities")
	public List<Teacher> teachers;

	@OneToMany(mappedBy = "activity",cascade= CascadeType.ALL)
	public List<Course> courses;

	public Activity(String name) {
		
		this.name = name;
		teachers = new LinkedList<Teacher>();
		courses = new LinkedList<Course>();
		
	}
	
	public LinkedList<Class> getActivityClasses(Date d) {
		
		LinkedList<Class> classes = new LinkedList<Class>();
				
		
		
		for(int i=0 ; i<courses.size(); i++) {
			
			List<Class> cs = courses.get(i).getCourseClasses();
			
			for(int j=0 ; j<cs.size(); j++) {
				
				Class c = cs.get(j);
				if(equivalent(c.datetime,d))classes.add(c);
				
			}
			
		}
		
		return classes;
		
	}

	private boolean equivalent(Date today, Date d) {
		
		return today.getDate() == d.getDate() &&
			   today.getMonth() == d.getMonth() &&
			   today.getYear() == d.getYear();
		
	}
	
	

}
